package com.oa.framework.org.department.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.oa.common.tree.TreeNode;
import com.oa.framework.org.domain.Duty;
import lombok.Getter;
import lombok.Setter;
import org.springframework.util.CollectionUtils;


import java.util.List;

/**
 * 部门
 * @author cuichao
 */
@Getter
@Setter
@TableName("org_department")
public class Department implements TreeNode<Department> {

    private static final String DEPARTMENT_NODE_TYPE = "department";
    /**
     * 部门ID
     */
    @TableId(value = "dep_id" , type = IdType.ASSIGN_ID)
    private Long departmentId;
    /**
     * 部门组织机构编码
     */
    @TableField("dep_code")
    private String departmentCode;
    /**
     * 部门名称
     */
    @TableField("dep_name")
    private String departmentName;
    /**
     * 上级部门Id
     */
    @TableField("dep_parent")
    private Long parentId;
    /**
     * 部门主管职务Id
     */
    @TableField("dep_master_duty")
    private Long masterDutyId;
    /**
     * 部门主管职位Id
     */
    @TableField("dep_master_post")
    private Long masterPositionId;
    /**
     * 是否废弃
     */
    @TableField("`disable`")
    private Boolean disable;
    /**
     * 部门主管职务
     */
    @TableField(exist = false)
    private Duty masterDuty;
    /**
     * 该部门所有的职务
     */
    @TableField(exist = false)
    private List<Duty> duties;
    /**
     * 上级部门
     */
    @TableField(exist = false)
    private Department parent;
    /**
     * 下级部门
     */
    @TableField(exist = false)
    private List<Department> children;

    @Override
    public Object getKey() {
        return departmentId;
    }

    @Override
    public String getName() {
        return departmentName;
    }

    @Override
    public Object getParentKey() {
        return parentId;
    }

    @Override
    public String getNodeType() {
        return DEPARTMENT_NODE_TYPE;
    }

    @Override
    public boolean hasLeaf() {
        return CollectionUtils.isEmpty(children);
    }
}
